
import * as sequelize from 'sequelize';
import C from '@jingli/config';
let DB;

export interface DBInitOptions { 
    url: string;
    forceSync?: boolean;
}

export async function init(conf: DBInitOptions) { 
    DB = new sequelize(conf.url);
    DB.models['Schedule'] = DB.import('./schedule');
    DB.models['Category'] = DB.import('./category');
    DB.models['User'] = DB.import('./user');
    DB.models['Token'] = DB.import('./token');
    DB.models['CategoryAttribute'] = DB.import('./category-attribute');
    DB.models['ScheduleAttribute'] = DB.import('./schedule-attribute');
    await DB.sync({ force: conf.forceSync });
}

export default DB;
export {DB}